<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <div class="seacrhMoney">
        <el-form-item>
          <div class="balance-searchMoney">
            结算单号
            <el-input class="input" v-model="dataForm.userName" placeholder="请输入结算单号"></el-input>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="balance-searchMoney">
            结算时间
            <el-date-picker v-model="value" type="daterange" value-format="yyyy-MM-dd HH:mm:ss" @change="lastTime" class="input" :clearable='false' start-placeholder="开始日期" end-placeholder="结束日期">
            </el-date-picker>
          </div>
        </el-form-item>
      </div>
      <el-form-item>
        <div class="balance-searchMoney">
          结算对象
          <el-select v-model="value1" filterable placeholder="请选择">
            <el-option v-for="item in city" :key="item.legalAccountCode" :label="item.legalCompanyName" :value="item.legalAccountCode">
            </el-option>
          </el-select>
        </div>
      </el-form-item>
      <el-form-item>
        <div class="balance-searchMoney">
          状态
          <el-select v-model="value2" filterable placeholder="请选择">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="demand">查询</el-button>
        <el-button type="primary" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- nav展示 -->
    <div class="nav">
      <div class="money" v-if="user==1" @click="hand" style="width: 24%;cursor:pointer">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ totalAccountAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item hand" effect="dark" content="平台当前可提现总金额（扣除手续费后）" placement="top-start">
            <div class="newTitle">
              <div class="two">账户总余额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/one.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <div class="money" v-if="user!=1" style="width: 24%;cursor:pointer">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ totalAccountAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item hand" effect="dark" content="平台当前可提现总金额（扣除手续费后）" placement="top-start">
            <div class="newTitle">
              <div class="two">账户总余额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/one.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 平台收款总金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ totalPropertyAndHomeAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="平台物业费和到家服务订单的收款总金额（未扣除手续费）" placement="top-start">
            <div class="newTitle">
              <div class="two">平台收款总金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/平台收款总金额@3x.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 物业收款总金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ totalPropertyAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="平台物业费收款总金额（未扣除手续费）" placement="top-start">
            <div class="newTitle">
              <div class="two">物业收款总金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/two.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 到家订单收款总金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ totalHomeAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="平台到家服务订单的收款总金额（未扣除手续费）" placement="top-start">
            <div class="newTitle">
              <div class="two">到家订单收款总金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/到家订单收款总金额@3x.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 已结算金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{  alreadyAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="平台收款后，已经结算可提现的的总金额（扣除手续费后）" placement="top-start">
            <div class="newTitle">
              <div class="two">已结算金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/Three.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 昨日收款 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ lastAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="平台昨日收款总金额（未扣除手续费）" placement="top-start">
            <div class="newTitle">
              <div class="two">昨日收款</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/six.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 冻结金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ awaitAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="城市公司已申请提现，还在审批中的金额" placement="top-start">
            <div class="newTitle">
              <div class="two">冻结金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/four.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 昨日申请提现金额 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ lastAwaitAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="昨日各城市公司申请提现的金额" placement="top-start">
            <div class="newTitle">
              <div class="two">昨日申请提现金额</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/seven.svg" alt="" class="moneyImg" />
        </div>
      </div>
      <!-- 昨日打款 -->
      <div class="money" style="width: 24%">
        <div class="moneyLeft">
          <div class="one">
            <span style="font-size: 14px">￥</span>{{ lastAgentAmount | MoneyFormat }}
          </div>
          <el-tooltip class="item" effect="dark" content="昨日各城市公司申请提现打款成功的金额（扣除手续费后）" placement="top-start">
            <div class="newTitle">
              <div class="two">昨日打款</div>
              <i name="wenhao" class="el-icon-question wenhao"></i>
            </div>
          </el-tooltip>
        </div>
        <div class="moneyRight">
          <img src="../../assets/img/five.svg" alt="" class="moneyImg" />
        </div>
      </div>

      <div class="money" style="background-color: #f0f2f5; width: 24%"></div>
    </div>
    <!-- 表格 -->
    <el-table :data="dataList" v-loading="dataListLoading" element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" element-loading-custom-class="loading_color">
      <template slot="empty">
        <img class="machine" src="../../assets/img/machine.svg" alt="" />
        <div style="font-size: 14px; text-align: center">暂无数据</div>
      </template>
      <el-table-column prop="cycleNo" header-align="center" align="center" label="结算单号">
        <template slot-scope="scope">
          <div class="cycleNos">
            <div @click="settlement(scope.row.cycleNo)">
              {{ scope.row.cycleNo }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="cycleTotalFee" header-align="center" align="center" label="结算金额(元)">
        <template slot-scope="scope">
          <div>{{ scope.row.cycleTotalFee| MoneyFormat }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="legalCompanyName" header-align="center" align="center" label="结算对象">
      </el-table-column>
      <el-table-column prop="settlementTime" header-align="center" align="center" label="结算时间">
      </el-table-column>
      <el-table-column prop="status" header-align="center" align="center" label="状态">
        <template slot-scope="scope">
          <div v-if="scope.row.withdrawStatus === 0" class="blueMoney">
            未提现
          </div>
          <div v-if="scope.row.withdrawStatus === 1" class="orangeMoney">
            审批中
          </div>
          <div v-if="scope.row.withdrawStatus === 2" class="greenMoney">
            已提现
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="withdrawTime" header-align="center" align="center" label="申请提现时间">
      </el-table-column>
      <el-table-column prop="withdrawProposer" header-align="center" align="center" label="申请提现人">
      </el-table-column>
      <!-- <el-table-column prop="legalCompanyName" header-align="center" align="center" label="申请提现单位">
      </el-table-column> -->
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.withdrawStatus != 0" type="text" size="small" :data-id="scope.row.id" @click="addOrUpdateHandle(scope.row.cycleNo)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "./balanceDetails-add-or-update.vue";
export default {
  data () {
    return {
      dataForm: {
        userName: "",
      },
      user: '',
      lastTimes: [],
      dataList: [],
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,
      value1: "",
      value2: "",
      withdrawAmount: "",
      awaitAmount: "",
      alreadyAmount: "",
      totalAmount: "",
      lastAmount: "",
      totalHomeAmount: '',
      lastAwaitAmount: "",
      totalAccountAmount: "",
      lastAgentAmount: "",
      totalPropertyAmount: '',
      totalPropertyAndHomeAmount: '',
      city: [],
      value: "",
      options: [
        {
          value: "0",
          label: "未提现",
        },
        {
          value: "1",
          label: "审批中",
        },
        {
          value: "2",
          label: "已提现",
        },
      ],
      cycleNo: "",
      withdrawTimeStart: "",
      withdrawTimeEnd: "",
      withdrawStatus: "",
      legalAccountCode: "",
      settlementTimeStart: "",
      settlementTimeEnd: "",
    };
  },
  components: {
    AddOrUpdate,
  },
  activated () {
    this.user = localStorage.getItem("user");
    this.getDataList();
    this.cityList();
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/balanceDetail/selectBalanceDetailList"
        ),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          withdrawTimeStart: this.withdrawTimeStart,
          settlementTimeStart: this.settlementTimeStart,
          settlementTimeEnd: this.settlementTimeEnd,
          withdrawTimeEnd: this.withdrawTimeEnd,
          withdrawStatus: this.withdrawStatus,
          cycleNo: this.cycleNo,
          legalAccountCode: this.legalAccountCode,
        }),
      }).then(({ data }) => {
        if (data.success === 1) {
          console.log(data.data)
          this.dataList = data.data.pageInfo.list;
          this.totalPage = data.data.pageInfo.total;
          this.withdrawAmount = data.data.adminBalanceAmount.withdrawAmount;
          this.awaitAmount = data.data.adminBalanceAmount.awaitAmount;
          this.alreadyAmount = data.data.adminBalanceAmount.alreadyAmount;
          this.totalAmount = data.data.adminBalanceAmount.totalAmount;
          this.lastAmount = data.data.adminBalanceAmount.lastAmount;
          this.lastAwaitAmount = data.data.adminBalanceAmount.lastAwaitAmount;
          this.totalAccountAmount = data.data.adminBalanceAmount.totalAccountAmount;
          this.lastAgentAmount = data.data.adminBalanceAmount.lastAgentAmount;
          this.totalHomeAmount = data.data.adminBalanceAmount.totalHomeAmount;
          this.totalPropertyAmount = data.data.adminBalanceAmount.totalPropertyAmount;
          this.totalPropertyAndHomeAmount = data.data.adminBalanceAmount.totalPropertyAndHomeAmount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/balanceDetail/selectBalanceDetailList"
        ),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          withdrawTimeStart: this.withdrawTimeStart,
          settlementTimeStart: this.lastTimes[0] || '',
          settlementTimeEnd: this.lastTimes[1] || '',
          withdrawTimeEnd: this.withdrawTimeEnd,
          withdrawStatus: this.value2,
          cycleNo: this.dataForm.userName,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success === 1) {
          console.log(data.data)
          this.dataList = data.data.pageInfo.list;
          this.totalPage = data.data.pageInfo.total;
          this.withdrawAmount = data.data.adminBalanceAmount.withdrawAmount;
          this.awaitAmount = data.data.adminBalanceAmount.awaitAmount;
          this.alreadyAmount = data.data.adminBalanceAmount.alreadyAmount;
          this.totalAmount = data.data.adminBalanceAmount.totalAmount;
          this.lastAmount = data.data.adminBalanceAmount.lastAmount;
          this.lastAwaitAmount = data.data.adminBalanceAmount.lastAwaitAmount;
          this.totalAccountAmount = data.data.adminBalanceAmount.totalAccountAmount;
          this.lastAgentAmount = data.data.adminBalanceAmount.lastAgentAmount;
          this.totalHomeAmount = data.data.adminBalanceAmount.totalHomeAmount;
          this.totalPropertyAmount = data.data.adminBalanceAmount.totalPropertyAmount;
          this.totalPropertyAndHomeAmount = data.data.adminBalanceAmount.totalPropertyAndHomeAmount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val;
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/balanceDetail/selectBalanceDetailList"
        ),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          withdrawTimeStart: this.withdrawTimeStart,
          settlementTimeStart: this.lastTimes[0] || '',
          settlementTimeEnd: this.lastTimes[1] || '',
          withdrawTimeEnd: this.withdrawTimeEnd,
          withdrawStatus: this.value2,
          cycleNo: this.dataForm.userName,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success === 1) {
          console.log(data.data)
          this.dataList = data.data.pageInfo.list;
          this.totalPage = data.data.pageInfo.total;
          this.withdrawAmount = data.data.adminBalanceAmount.withdrawAmount;
          this.awaitAmount = data.data.adminBalanceAmount.awaitAmount;
          this.alreadyAmount = data.data.adminBalanceAmount.alreadyAmount;
          this.totalAmount = data.data.adminBalanceAmount.totalAmount;
          this.lastAmount = data.data.adminBalanceAmount.lastAmount;
          this.lastAwaitAmount = data.data.adminBalanceAmount.lastAwaitAmount;
          this.totalAccountAmount = data.data.adminBalanceAmount.totalAccountAmount;
          this.lastAgentAmount = data.data.adminBalanceAmount.lastAgentAmount;
          this.totalHomeAmount = data.data.adminBalanceAmount.totalHomeAmount;
          this.totalPropertyAmount = data.data.adminBalanceAmount.totalPropertyAmount;
          this.totalPropertyAndHomeAmount = data.data.adminBalanceAmount.totalPropertyAndHomeAmount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 城市列表
    // 获取数据列表
    cityList () {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/legalCompany/getByCurrentFinanceCode"
        ),
        method: "get",
        params: this.$http.adornParams({}),
      }).then(({ data }) => {
        if (data.success === 1) {
          this.city = data.data;
        } else {
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    //清空
    empty () {
      this.dataForm.userName = ''
      this.value = ''
      this.value1 = ''
      this.value2 = ''
      this.getDataList()
    },
    //查询
    demand () {
      this.pageIndex = 1
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl(
          "cassadmin/balanceDetail/selectBalanceDetailList"
        ),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          size: this.pageSize,
          withdrawTimeStart: this.withdrawTimeStart,
          settlementTimeStart: this.lastTimes[0] || '',
          settlementTimeEnd: this.lastTimes[1] || '',
          withdrawTimeEnd: this.withdrawTimeEnd,
          withdrawStatus: this.value2,
          cycleNo: this.dataForm.userName,
          legalAccountCode: this.value1,
        }),
      }).then(({ data }) => {
        if (data.success === 1) {
          console.log(data.data)
          this.dataList = data.data.pageInfo.list;
          this.totalPage = data.data.pageInfo.total;
          this.withdrawAmount = data.data.adminBalanceAmount.withdrawAmount;
          this.awaitAmount = data.data.adminBalanceAmount.awaitAmount;
          this.alreadyAmount = data.data.adminBalanceAmount.alreadyAmount;
          this.totalAmount = data.data.adminBalanceAmount.totalAmount;
          this.lastAmount = data.data.adminBalanceAmount.lastAmount;
          this.lastAwaitAmount = data.data.adminBalanceAmount.lastAwaitAmount;
          this.totalAccountAmount = data.data.adminBalanceAmount.totalAccountAmount;
          this.lastAgentAmount = data.data.adminBalanceAmount.lastAgentAmount;
          this.totalHomeAmount = data.data.adminBalanceAmount.totalHomeAmount;
          this.totalPropertyAmount = data.data.adminBalanceAmount.totalPropertyAmount;
          this.totalPropertyAndHomeAmount = data.data.adminBalanceAmount.totalPropertyAndHomeAmount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
          this.$message.error(data.errorMsg);
        }
        this.dataListLoading = false;
      });
    },
    // 对账信息
    hand () {
      this.$router.push({
        name: `totalFinance-reconciliation`
      })
    },
    // 时间
    lastTime (e) {
      this.lastTimes = e
    },
    // 查看详情
    addOrUpdateHandle (cycleNo) {
      this.$router.push({
        name: `totalFinance-WithdrawalRecord`,
        query: {
          cycleNo: cycleNo,
        },
      });
      // this.addOrUpdateVisible = true;
      // this.$nextTick(() => {
      //   this.$refs.addOrUpdate.init(cycleNo);
      // });
    },
    // 结算账单页面
    settlement (cycleNo) {
      this.$router.push({
        name: `totalFinance-settlementList`,
        query: {
          cycleNo: cycleNo,
        },
      });
    },
  },
};
</script>
<style scoped>
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
.nav {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.money {
  height: 100px;
  background-color: #fff;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  border-radius: 6px;
  margin-bottom: 24px !important;
}

.money div {
  color: #333;
  box-sizing: border-box;
}
.one {
  font-size: 20px;
  font-weight: 500;
  color: #000;
  margin-top: 20px;
  margin-bottom: 5px;
}
.money .two {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
.moneyRight {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}
.moneyImg {
  width: 72px;
  height: 72px;
}

.f16 {
  font-size: 16px;
}
.moneyLeft {
  flex: 1;
  text-align: center;
}
</style>
